package com.xqt.controller;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xqt.base.entity.BaseEntity;
import com.xqt.base.page.BasePage;
import com.xqt.base.page.PageInfo;
import com.xqt.entity.message.MessageBase;
import com.xqt.entity.sys.SysMenuBtn;
import com.xqt.inters.service.message.IMessageService;
import com.xqt.inters.service.sys.ISysMenuBtnService;


@RestController
@RequestMapping(value = "/message")
public class MainController {
	
	@Autowired
	IMessageService messageService;
	@Autowired
	ISysMenuBtnService menuBtnService;
	
	@RequestMapping("/list")
	public List<MessageBase> testList(){
		BaseEntity page = new MessageBase();
		page.setLimitDirection(true);
		return messageService.queryList(page);
	}
	
	
	@RequestMapping("/page")
	public List<MessageBase> testPage(){
		BaseEntity page = new MessageBase();
		page.setLimitDirection(true);
		return messageService.queryByList(page);
	}
	
	@RequestMapping("/menuPage")
	public Map<String, Object> getBtn(){
		BaseEntity page = new SysMenuBtn();
		page.setLimitDirection(true);
		List<SysMenuBtn> dataList = menuBtnService.queryPageList(page);
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("datalist", dataList);
		return map;
	}
	
	@RequestMapping("/pageList")
	public List<SysMenuBtn> getPageList(){
		BaseEntity page = new SysMenuBtn();
		List<SysMenuBtn> dataList = menuBtnService.queryPageList(page);
		return dataList;
	}
	@RequestMapping("/pageInfo")
	public PageInfo<SysMenuBtn> getPageInfo(){
		BaseEntity entity = new SysMenuBtn();
		PageInfo<SysMenuBtn> pages = menuBtnService.queryPageInfo(entity);
		pages.getData();
		pages.getPageCount();
		pages.getRowCount();
		System.out.println(pages.getRowCount());
		System.out.println(pages.getPageCount());
		
		return pages;
	}
	
	@RequestMapping("/testCustomE")
	public PageInfo<SysMenuBtn> getPageInfoByEntity(){
		SysMenuBtn entity = new SysMenuBtn();
		String countMethod = "queryByCount";
		String sqlMethod = "queryEntityList";
		entity.setLimitDirection(true);
		return menuBtnService.selectPageByEntity(entity, countMethod, sqlMethod);
	}
	
	
	@RequestMapping("/testMap")
	public Object getMap(){
		SysMenuBtn entity = new SysMenuBtn();
		List<Map<String, Object>> list = menuBtnService.selectEntityList(entity, "queryByMap");
		return list;
	}
	
	@RequestMapping("/testPageIdex")
	public PageInfo<SysMenuBtn> getPageInfoByI(SysMenuBtn entity){
		return menuBtnService.selectPageListCustom(entity, "queryByCount", "queryEntityListByPageSizeAndPageIndex", 2, 5);
	}
}
